home *** CD-ROM | disk | FTP | other *** search
- #include <Dialogs.h>
- #include <GestaltEqu.h>
- #ifndef __TYPES__
- #include <Types.h>
- #endif
-
- #ifndef __MEMORY__
- #include <Memory.h>
- #endif
-
- #ifndef __ERRORS__
- #include <Errors.h>
- #endif
-
- #ifndef __TRAPS__
- #include <Traps.h>
- #endif
-
- #ifndef __OSUTILS__
- #include <OSUtils.h>
- #endif
-
- #ifndef __TOOLUTILS__
- #include <ToolUtils.h>
- #endif
-
- #include <Resources.h>
- #include "OSUtilsSup.h"
-
- pascal void ShowINIT(short iconID, short moveX);
- pascal void MessageModalDialog(ModalFilterProcPtr filterProc,short *itemHit);
- pascal OSErr MessageGestalt(OSType selector, long *response);
- pascal Boolean MessageFilterProc(DialogPtr theDialog, EventRecord* theEvent, short* itemHit);
- void foo(void);
- void globals(void);
-
- void main(void)
- {
-
- QHdrPtr q = (QHdrPtr)foo;
-
- q->qFlags = 0;
- q->qHead = 0;
- q->qTail = 0;
-
- NewGestalt('Msg!',(ProcPtr)MessageGestalt);
-
- (void)PatchTrap((ProcPtr*)globals, _ModalDialog, (ProcPtr)MessageModalDialog, 0);
- DetachResource(RecoverHandle((Ptr)main));
-
- ShowINIT(128,-1);
-
- }
-
- void globals(void)
- {
- Debugger();
- Debugger();
- Debugger();
- Debugger();
- Debugger();
- Debugger();
- Debugger();
- Debugger();
- }
-
- void foo(void)
- {
- Debugger();
- Debugger();
- Debugger();
- Debugger();
- Debugger();
- Debugger();
- Debugger();
- Debugger();
- }
-
- pascal OSErr MessageGestalt(OSType, long *response)
- {
- *response = (long)foo;
- return noErr;
- }
-
- typedef struct {
- char blank[6];
- PicHandle picture;
- } Q;
-
- typedef pascal void (*SModalDialog)(ModalFilterProcPtr, short*);
-
- typedef struct {
- long refCon;
- long ticks;
- ModalFilterProcPtr filterProc;
- short stage;
- Boolean timedOut;
- } Locals;
-
- pascal void MessageModalDialog(ModalFilterProcPtr filterProc,short *itemHit)
- {
- PicHandle picture;
- GrafPtr theDialog;
- THz zone;
- Q* q;
- GrafPtr oldPort;
- QHdrPtr qHeader;
- short itemType;
- Handle handle;
- Rect box;
- Str255 title;
- Locals locals;
-
- theDialog = FrontWindow();
-
- GetDItem(theDialog, ok, &itemType, &handle, &box);
-
- if (itemType != 4) goto bannana;
- GetCTitle((ControlHandle)handle, title);
- if (title[0] != 2) goto bannana;
- if (title[1] != 'O') goto bannana;
- if (title[2] != 'K') goto bannana;
-
- locals.filterProc = filterProc;
- locals.refCon = ((WindowPeek)theDialog)->refCon;
- locals.ticks = TickCount();
- locals.timedOut = false;
- locals.stage = 0;
-
- ((WindowPeek)theDialog)->refCon = &locals;
-
- #define CallTheOldTrap (*((SModalDialog*)globals))
-
- CallTheOldTrap(MessageFilterProc, itemHit);
-
- ((WindowPeek)theDialog)->refCon = locals.refCon;
-
- if (!locals.timedOut) return;
-
- GetPort(&oldPort);
- SetPort(theDialog);
-
- zone = GetZone();
- SetZone(SystemZone());
- picture = OpenPicture(&theDialog->portRect);
- SetZone(zone);
-
- (*(ControlHandle)handle)->contrlHilite = inButton;
- DrawDialog(theDialog);
- (*(ControlHandle)handle)->contrlHilite = 0;
-
- ClosePicture();
-
- SetPort(oldPort);
-
- q = (Q*)NewPtrSys(6 + sizeof(PicHandle));
- q->picture = picture;
-
- if (Gestalt('Msg!', (long*)&qHeader) == noErr) Enqueue((QElemPtr)q, qHeader);
- else {
- DisposePtr((Ptr)q);
- KillPicture(picture);
- }
- SetPort(oldPort);
-
- *itemHit = ok;
- return;
- bannana:
- CallTheOldTrap(filterProc, itemHit);
- }
-
- enum {
- lastStage = 8, /* Dismiss Dialog when this stage is met */
- middleStage = 3, /* Invert button after middleStage */
- startTime = 60 * 10, /* Start to fade after 15 seconds */
- delayTime = (60 * 3) / lastStage /* Fade in 3 seconds */
- };
-
- pascal Boolean MessageFilterProc(DialogPtr theDialog, EventRecord* theEvent, short* itemHit)
- {
- Locals* locals = ((WindowPeek)theDialog)->refCon;
- short itemType;
- Handle handle;
- Rect box;
- GrafPtr currentPort;
- short patternIndex[] = { 21, 22, 23, 4, 23, 22, 21, 20 };
- Pattern pattern;
-
- if ((theEvent->what >= mouseDown) && (theEvent->what <= autoKey)) {
-
- /* Brighten the control */
-
- if (locals->stage != 0) {
- GetDItem(theDialog, ok, &itemType, &handle, &box);
- Draw1Control((ControlHandle)handle);
- locals->stage = 0;
- }
-
- /* Reset the timer */
-
- locals->ticks = TickCount();
-
- } else if (locals->ticks + startTime + (locals->stage) * delayTime < TickCount()) {
- if (locals->stage == lastStage) {
- *itemHit = ok;
- locals->timedOut = true;
-
- return true;
- }
- GetDItem(theDialog, ok, &itemType, &handle, &box);
- GetPort(¤tPort);
- SetPort(theDialog);
- if (locals->stage > middleStage) {
- (*(ControlHandle)handle)->contrlHilite = inButton;
- Draw1Control((ControlHandle)handle);
- (*(ControlHandle)handle)->contrlHilite = 0;
- PenMode(patBic);
- } else {
- Draw1Control((ControlHandle)handle);
- PenMode(patOr);
- }
- GetIndPattern(&pattern, sysPatListID, patternIndex[locals->stage]);
- PenPat(&pattern);
- PaintRoundRect(&box, 10, 10);
- PenNormal();
- SetPort(currentPort);
- ++locals->stage;
- }
-
- if (locals->filterProc) {
- Boolean result;
-
- ((WindowPeek)theDialog)->refCon = locals->refCon;
- result = locals->filterProc(theDialog, theEvent, itemHit);
- ((WindowPeek)theDialog)->refCon = locals;
- return result;
- } else return false;
- }
-
-
-